home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / comm / tcp / Amster.lha / Amster_Install / Source / sound.c < prev    next >
C/C++ Source or Header  |  2000-06-05  |  2KB  |  86 lines

  1. /*
  2. ** Datatype Sound Player
  3. */
  4.  
  5. #include "include/config.h"
  6.  
  7. #include <proto/exec.h>
  8. #include <proto/datatypes.h>
  9. #include <proto/dtclass.h>
  10. #include <clib/datatypes_protos.h>
  11. #include <clib/alib_protos.h>
  12. #include <datatypes/datatypes.h>
  13. #include <datatypes/datatypesclass.h>
  14. #include <datatypes/soundclass.h>
  15.  
  16. #include "include/thread.h"
  17.  
  18. void __asm __saveds snd_player(void);
  19.  
  20.  
  21. void snd_play(char *fname)
  22. {
  23.     if (!fname) return;
  24.     th_spawn(NULL, "Amster sound player", snd_player, 0, fname);
  25. }
  26.  
  27.  
  28. void __asm __saveds snd_player(void)
  29. {
  30.     thread t;
  31.     struct Library *DosBase;
  32.     struct Library *DataTypesBase;
  33.     Object *sample;
  34.     struct dtTrigger trigger;
  35.     long ssig, tsig;
  36.  
  37.     t = thr_init();
  38.     if (!t) return;
  39.     tsig = (1L << (t->port->mp_SigBit));
  40.  
  41.     DosBase = OpenLibrary("dos.library", 36);
  42.     if (!DosBase) {
  43.         thr_exit(t, 1);
  44.         return;
  45.     }
  46.     DataTypesBase = OpenLibrary("datatypes.library", 39);
  47.     if (!DataTypesBase) {
  48.         CloseLibrary(DosBase);
  49.         thr_exit(t, 1);
  50.         return;
  51.     }
  52.  
  53.     ssig = AllocSignal(-1);
  54.     if (ssig == -1) {
  55.         CloseLibrary(DataTypesBase);
  56.         CloseLibrary(DosBase);
  57.         thr_exit(t, 1);
  58.         return;
  59.     }
  60.  
  61.     sample = NewDTObject((char*)t->data, DTA_GroupID, GID_SOUND, TAG_DONE);
  62.     if (!sample) {
  63.         FreeSignal(ssig);
  64.         CloseLibrary(DataTypesBase);
  65.         CloseLibrary(DosBase);
  66.         thr_exit(t, 2);
  67.         return;
  68.     }
  69.  
  70.     SetDTAttrs(sample,NULL,NULL,SDTA_SignalBit,(1L << ssig),SDTA_SignalTask,t->task,TAG_DONE);
  71.  
  72.     trigger.MethodID = DTM_TRIGGER;
  73.     trigger.dtt_GInfo = NULL;
  74.     trigger.dtt_Function = STM_PLAY;
  75.     trigger.dtt_Data = NULL;
  76.     DoDTMethodA(sample, 0L, 0L, (Msg)&trigger);
  77.  
  78.     Wait((1L<<ssig)|tsig|SIGBREAKF_CTRL_C);
  79.  
  80.     DisposeDTObject(sample);
  81.     FreeSignal(ssig);
  82.     CloseLibrary(DataTypesBase);
  83.     CloseLibrary(DosBase);
  84.     thr_exit(t, 0);
  85. }
  86.